# st - simple terminal
# See LICENSE file for copyright and license details.
.POSIX:

include src/config.mk

SRC = src/st.c src/x.c
OBJ = $(SRC:.c=.o)

all: options st

options:
	@echo st build options:
	@echo "CFLAGS  = $(STCFLAGS)"
	@echo "LDFLAGS = $(STLDFLAGS)"
	@echo "CC      = $(CC)"

config.h:
	cp src/config.def.h src/config.h

.c.o:
	$(CC) $(STCFLAGS) -c $< -o $@

st.o: src/config.h src/st.h src/win.h
x.o: src/arg.h src/config.h src/st.h src/win.h

$(OBJ): src/config.h src/config.mk

prepare:
	mkdir -p bin

st: $(OBJ)
	mkdir -p bin
	$(CC) -o bin/$@ $(OBJ) $(STLDFLAGS)

clean:
	rm -f bin/st $(OBJ) st-$(VERSION).tar.gz
	rm -r bin

dist: clean
	mkdir -p st-$(VERSION)
	cp -R FAQ LEGACY TODO LICENSE Makefile README config.mk\
		config.def.h st.info st.1 arg.h st.h win.h $(SRC)\
		st-$(VERSION)
	tar -cf - st-$(VERSION) | gzip > st-$(VERSION).tar.gz
	rm -rf st-$(VERSION)

install: st
	mkdir -p ${DESTDIR}${PREFIX}/files/bin
	cp -f bin/st ${DESTDIR}${PREFIX}/files/bin
	chmod 755 ${DESTDIR}${PREFIX}/files/bin/st
	tic -sx st.info

uninstall:
	rm -f $(DESTDIR)$(PREFIX)/files/bin/st

.PHONY: all options clean dist install uninstall
